﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using System.Web;
using Antu.WorkFlowFactory;
using System.Data;

namespace WebSys.UI.OfficeFlow
{
    public class DepartlistSkin : MPBasicTemplate
    {
        FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
        public static string strHtml;
        protected string UserId
        {
            get { if (base.Page.Session["UserId"] != null) { return base.Page.Session["UserId"].ToString(); } else { return string.Empty; } }
            set { base.Page.Session["UserId"] = value; }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }
        protected void BindData() {
            string strDepID = base.Page.Request["DepID"];  //要移动的部门id
            string strWay = base.Page.Request["UpDown"];//移动方向
            if (!string.IsNullOrEmpty(strDepID) && !string.IsNullOrEmpty(strWay))
            {
                _FlowFactoryProvider.MoveDepart(strDepID, strWay);
            }
            DataTable dtDepart = _FlowFactoryProvider.GetAllDeptInfo();
            MPRepeater MPRepeater1 = (MPRepeater)FindControl("MPRepeater1");
            MPRepeater1.DataSource = dtDepart;
            MPRepeater1.DataBind();

            //string SystempUser = "2";
            //string strUser = UserId;
            //////获取登陆用户的部门ID
            ////DataTable dtUserDepart = _FlowFactoryProvider.GetDptIdByUserId(strUser);
            ////if (dtUserDepart.Rows.Count > 0)
            ////{
            ////    ////判定是否属于办公室人员(管理员)
            ////    //bool isTrue = false;
            ////    //for (int i = 0; i < dtUserDepart.Rows.Count; i++)
            ////    //{
            ////    //    if (dtUserDepart.Rows[i][0].ToString() == SystempUser)
            ////    //    {
            ////    //        dtDepart = _FlowFactoryProvider.GetAllDeptInfo();
            ////    //        isTrue = true;
            ////    //        break;
            ////    //    }
            ////    //}
            ////    ////如果属于非办公室人员
            ////    //if (!isTrue)
            ////    //{
            ////    //    dtDepart = _FlowFactoryProvider.GetHasRightDep(dtUserDepart.Rows[0][0].ToString());
            ////    //}
            ////    //上面代码只能显示两级部门，以下代码可显示多级
                
            ////}

            //dtDepart.DefaultView.RowFilter = "parent_id=0";
            //System.Data.DataView dvParent = dtDepart.DefaultView;
            //foreach (System.Data.DataRowView drvParent in dvParent)
            //{
            //    string depName = drvParent["DEPART_NAME"].ToString();
            //    string orderId = drvParent["ORDER_ID"].ToString();
            //    string departId = drvParent["DEPARTID"].ToString();
            //    string strHtml = string.Empty;

            //    dtDepart.DefaultView.RowFilter = string.Format("parent_id={0}", departId);
            //    System.Data.DataView dvChild = dtDepart.DefaultView;

            //    if (dvChild.Count > 0)
            //    {
            //        strHtml = string.Format("<li><a href=\"javascript:onClickForTree('{0}','{1}','{2}');void(0);\">{1}</a><img style=\"cursor:pointer\" src=\"tree/moveup.gif\" onclick=\"MoveDep('{2}','up')\"/><img style=\"cursor:pointer\" src=\"tree/movedown.gif\" onclick=\"MoveDep('{2}','down')\"/><ul>",
            //          orderId, depName, departId);
            //    }
            //    else
            //    {
            //        strHtml = string.Format("<li><a href=\"javascript:onClickForTree('{0}','{1}','{2}');void(0);\">{1}</a><img style=\"cursor:pointer\" src=\"tree/moveup.gif\" onclick=\"MoveDep('{2}','up')\"/><img style=\"cursor:pointer\" src=\"tree/movedown.gif\" onclick=\"MoveDep('{2}','down')\"/></li>",
            //           orderId, depName, departId);
            //    }

            //    foreach (System.Data.DataRowView drvChild in dvChild)
            //    {
            //        strHtml += string.Format("<li><a href=\"javascript:onClickForTree('{0}','{1}','{2}');void(0);\">{1}</a><img style=\"cursor:pointer\" src=\"tree/moveup.gif\" onclick=\"MoveDep('{2}','up')\"/><img style=\"cursor:pointer\" src=\"tree/movedown.gif\" onclick=\"MoveDep('{2}','down')\"/></li>",
            //           drvChild["ORDER_ID"], drvChild["DEPART_NAME"], drvChild["DEPARTID"]);
            //    }
            //    if (dvChild.Count > 0)
            //    {
            //        strHtml += "</li></ul>";
            //    }
            //    //base.Page.Response.Write(strHtml);

            //}
            
        }

    }
}


